<?php namespace App\Exceptions;

use Exception;

class DataException extends Exception
{

    const DataSaveError      = 0x01;
    const NotExistError      = 0x02;
    const DeleteError        = 0x03;
    const RequestDataIsWrong = 0x04;
    const QuestionIsTosloft  = 0x05;
    const AnswerIsTosloft    = 0x05;

    public function __construct($code, array $data = [], Exception $previous = null)
    {
        switch ($code) {
            case self::DataSaveError:
                $message = trans('数据保存失败！');
                break;
            case self::NotExistError:
                $message = trans('数据不存在！');
                break;
            case self::DeleteError:
                $message = trans('数据删除失败！');
                break;
            case self::RequestDataIsWrong:
                $message = trans('请求数据格式不正确！');
                break;
            case self::QuestionIsTosloft:
                $message = trans('提问内容不能少于6个字！');
                break;
            case self::AnswerIsTosloft:
                $message = trans('回答内容不少于6个字或不大于250字！');
                break;
            default:
                $message = trans('未知错误');
                break;
        }

        parent::__construct($message, $code, $previous);
    }

}